import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2024-11-13
 * Time: 21:42
 */
public class Test2 {
    public static void main(String[] args) {
        // 定时器：底层通过一个线程来执行任务，可以指定执行的先后顺序
        Timer timer = new Timer();

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("3000ms后执行任务1");
            }
        }, 3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("2000ms后执行任务2");
            }
        }, 2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("1000ms后执行任务3");
            }
        }, 1000);
    }
}
